package com.lmr.boot.config;

import com.lmr.boot.interceptor.LoginInterceptor;
import com.lmr.boot.interceptor.RedisUrlCount;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {
    /**
     * Filter ，interceptor  区别
     * Filter是Servlet定义的原生组件，好处，脱离spring应用也能用
     * interceptor是spring定义的接口，可以使用自动装配的功能
     */
    @Autowired
    RedisUrlCount redisUrlCount;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginInterceptor())//把拦截器放入容器中
                .addPathPatterns("/**")//配置拦截的路径
                .excludePathPatterns("/login","/abc","/", "/css/**","/fonts/**","/images/**","/js/**","/echarts-5.1.1/**");//配置放行的路径
        registry.addInterceptor(redisUrlCount)
                .addPathPatterns("/**")
                .excludePathPatterns("/login","/abc","/", "/css/**","/fonts/**","/images/**","/js/**","/echarts-5.1.1/**");//配置放行的路径
    }
}
